package com.lyhengtongwl.zqsnews.adapter;

import android.annotation.SuppressLint;
import android.content.Context;
import android.support.annotation.Nullable;
import android.widget.ImageView;
import android.widget.TextView;
import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.squareup.picasso.Picasso;
import com.lyhengtongwl.zqsnews.App;
import com.lyhengtongwl.zqsnews.R;
import com.lyhengtongwl.zqsnews.entity.BidRecordEntity;

import java.util.List;

/**
 * Created by Steven on 2019/2/17.
 */
public class DetailsBisRecordAdapter extends BaseQuickAdapter<BidRecordEntity, BaseViewHolder> {
    private Context mContext;

    public DetailsBisRecordAdapter(Context mContext, @Nullable List<BidRecordEntity> data) {
        super(R.layout.bids_item, data);
        this.mContext = mContext;
    }

    @SuppressLint("SetTextI18n")
    @Override
    protected void convert(BaseViewHolder helper, BidRecordEntity item) {
        Picasso.with(App.getContext()).load(item.getUrl()).resize(dip2px(250), dip2px(250)).into(((ImageView) helper.getView(R.id.iv_img)));
        int position = helper.getPosition();
        switch (position) {
            case 0:
                helper.getView(R.id.ll_bidItem).setBackground(mContext.getResources().getDrawable(R.drawable.bids_top_shape));
                ((TextView) helper.getView(R.id.tv_status)).setText("领先");
                ((TextView) helper.getView(R.id.tv_name)).setTextColor(mContext.getResources().getColor(R.color.mainBg));
                ((TextView) helper.getView(R.id.tv_status)).setTextColor(mContext.getResources().getColor(R.color.mainBg));
                ((TextView) helper.getView(R.id.tv_address)).setTextColor(mContext.getResources().getColor(R.color.mainBg));
                ((TextView) helper.getView(R.id.tv_money)).setTextColor(mContext.getResources().getColor(R.color.mainBg));
                break;
            case 1:
                helper.getView(R.id.ll_bidItem).setBackground(mContext.getResources().getDrawable(R.drawable.bid_center_layer));
                ((TextView) helper.getView(R.id.tv_status)).setText("出局");
                ((TextView) helper.getView(R.id.tv_name)).setTextColor(mContext.getResources().getColor(R.color.black));
                ((TextView) helper.getView(R.id.tv_status)).setTextColor(mContext.getResources().getColor(R.color.black));
                ((TextView) helper.getView(R.id.tv_address)).setTextColor(mContext.getResources().getColor(R.color.black));
                ((TextView) helper.getView(R.id.tv_money)).setTextColor(mContext.getResources().getColor(R.color.black));
                break;
            case 2:
                helper.getView(R.id.ll_bidItem).setBackground(mContext.getResources().getDrawable(R.drawable.bids_bottom_shape));
                ((TextView) helper.getView(R.id.tv_status)).setText("出局");
                ((TextView) helper.getView(R.id.tv_name)).setTextColor(mContext.getResources().getColor(R.color.black));
                ((TextView) helper.getView(R.id.tv_status)).setTextColor(mContext.getResources().getColor(R.color.black));
                ((TextView) helper.getView(R.id.tv_address)).setTextColor(mContext.getResources().getColor(R.color.black));
                ((TextView) helper.getView(R.id.tv_money)).setTextColor(mContext.getResources().getColor(R.color.black));
                break;
        }
        ((TextView) helper.getView(R.id.tv_name)).setText(item.getPhone());
        ((TextView) helper.getView(R.id.tv_address)).setText(item.getAddress());
        ((TextView) helper.getView(R.id.tv_money)).setText(item.getMoney());
    }

    private int dip2px(float dpValue) {
        float scale = mContext.getResources()
                .getDisplayMetrics().density;
        return (int) (dpValue * scale + 0.5f);
    }
}
